package cn.iocoder.yudao.module.bk.controller.app.vo;

import cn.iocoder.yudao.module.bk.dal.dataobject.lwbook.LwBookDO;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.checkerframework.checker.units.qual.N;

import javax.validation.constraints.NotEmpty;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

/**
 * @author EDY
 */
@Schema(description = "app - 书记心思 req VO")
@Data
@NoArgsConstructor
@AllArgsConstructor
public class BookInfoReq {

    @Schema(description = "书名", requiredMode = Schema.RequiredMode.REQUIRED)
    @NotEmpty(message = "书名不能为空")
    private String title;

    @Schema(description = "封面图")
    private String img;

    @Schema(description = "简介")
    private String summary;

    @Schema(description = "isbn编号")
    @NotEmpty(message = "isbn编号不能为空")
    private String isbn;

    @Schema(description = "出版社")
    private String publisher;

    @Schema(description = "出版时间")
    private String pubDate;

    @Schema(description = "页数", example = "3697")
    private Integer pageCount;

    public BookInfoReq(IsbnApiVo isbnApiVo) {
        this.title = isbnApiVo.getTitle();
        this.img = isbnApiVo.getImg();
        this.summary = isbnApiVo.getSummary();
        this.isbn = isbnApiVo.getIsbn();
        this.publisher = isbnApiVo.getPublisher();
        this.pubDate = isbnApiVo.getPubdate();

        // String -> Integer 转换
        if (isbnApiVo.getPages() != null && !isbnApiVo.getPages().isEmpty()) {
            try {
                this.pageCount = Integer.parseInt(isbnApiVo.getPages());
            } catch (NumberFormatException e) {
                this.pageCount = null; // 或者设置默认值
            }
        }
    }
    public BookInfoReq(LwBookDO bookDO) {
        this.title = bookDO.getTitle();
        this.img = bookDO.getImg();
        this.summary = bookDO.getSummary();
        this.isbn = bookDO.getIsbn();
        this.publisher = bookDO.getPublisher();
        this.pubDate = bookDO.getPubDate();
        this.pageCount = bookDO.getPageCount();
    }

}
